<?php
//File:app/models/m_user.php
class MUser extends AppModel {
	var $name = 'MUser';
	
	function check_add(){
		$this->validate = array(
				'user_id' => array(
					'user_id_not_empty' => array(
						'rule' => 'notEmpty',
						'message' => 'This field is required',
						'last' => true
				),
					'user_id_unique' => array(
						'rule' => 'isUnique',
						'message' => 'This user ID is already in use',
						'last' => true
				),
					'user_id_format' => array(
						'rule' => '/^[s]{1}[u]{1}[c]{1}[0-9]{3}$/',
						'message' => 'This user ID is not correct format',
						'last' => true
				)
			),
				'user_name' => array(
					'user_name_not_empty' => array(
						'rule' => 'notEmpty',
						'message' => 'This field is required',
						'last' => true
				),
					'user_name_unique' => array(
						'rule' => 'isUnique',
						'message' => 'This username is already in use',
						'last' => true
				)
			),
			
				'email_address' => array(
					'email_not_empty' => array(
						'rule' => 'notEmpty',
						'message' => 'This field is required',
						'last' => true
				),
					'email_unique' => array(
						'rule' => 'isUnique',
						'message' => 'This email is already in use',
						'last' => true
				),
					'email_format' => array(
						'rule' => '/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/',
						'message' => 'This email is not correct email format',
						'last' => true
				)
			),
				'newPassword' => array(
					'password_not_empty' => array(
						'rule' => 'notEmpty',
						'message' => 'This field is required',
						'last' => true
					)
				)
			);
		
		if($this->validates($this->validate))
		return TRUE;
		else
		return FALSE;
	
	} //End check_add()
	
	function check_edit(){
		$this->validate = array(
					'user_id' => array(
						'user_id_not_empty' => array(
							'rule' => 'notEmpty',
							'message' => 'This field is required',
							'last' => true
						),
						'user_id_format' => array(
							'rule' => '/^[s]{1}[u]{1}[c]{1}[0-9]{3}$/',
							'message' => 'This user ID is not correct format',
							'last' => true
						)
			),
					'user_name' => array(
						'user_name_not_empty' => array(
							'rule' => 'notEmpty',
							'message' => 'This field is required',
							'last' => true
						),
			),
			
					'email_address' => array(
						'email_not_empty' => array(
							'rule' => 'notEmpty',
							'message' => 'This field is required',
							'last' => true
						),
						'email_format' => array(
							'rule' => '/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/',
							'message' => 'This email is not correct email format',
							'last' => true
						)
			),
					'newPassword' => array(
						'password_not_empty' => array(
							'rule' => 'notEmpty',
							'message' => 'This field is required',
							'last' => true
						)
			)
			
		);
	
		if($this->validates($this->validate))
		return TRUE;
		else
		return FALSE;
	} //End check_edit()

	function ComparePass(){
		if($this->data['MUser']['new_password']!=$this->data['MUser']['re_new_password']){
			return FALSE;
		}
		else{
			return TRUE;
		}
	}
}
?>